<?php
$idSP = (int) $_GET['idSP'];
$rs_ct = $sp ->getDetailSP($idSP);
$row_ct = mysql_fetch_assoc($rs_ct);
if(isset($_POST['btnSumit'])){			
    $thanhcong = $sp->SanPham_Sua($idSP,$loi);	
    if($thanhcong==true){		
            header("location:?com=sp_list");
    }
}
?>
<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="ckfinder/ckfinder.js"></script>
<link rel="stylesheet" type="text/css" href="css/jquery.ui.all.css"/>
<link rel="stylesheet" type="text/css" href="css/jquery.ui.datepicker.css"/>
<script type="text/javascript" src="js/form.js"></script>
<script type="text/javascript" src="js/jquery.ui.widget.js"></script>
<script type="text/javascript" src="js/jquery.ui.datepicker.js"></script>
<script type="text/javascript" src="js/jquery-ui.custom.js"></script>
<script type="text/javascript" src="js/jquery.ui.dialog.js"></script>
<script type="text/javascript">
	$(document).ready(function(){
		$('#upload_images').ajaxForm({
                        beforeSend: function() {				
			},
			uploadProgress: function(event, position, total, percentComplete) {
				           
			},
			complete: function(data) {       
				var arrRes = JSON.parse(data.responseText); 
				alert(arrRes['thongbao']);
				$("#hinhanh").html(arrRes['text'] + arrRes['str_hinhanh']);
				$( "#div_upload" ).dialog('close');				
			}
                }); 
		$("#btnUpload").click(function(){			
			$("#div_upload" ).dialog({
				modal: true,
				title: 'Upload images',
				width: 350,
				draggable: true,
				resizable: false,
				position: "center middle"
			});
		});
		$("#add_images").click(function(){
			$( "#wrapper_input_files" ).append("<input type='file' name='images[]' /><br />");
		});
                $('span.xoa_img').click(function(){
                    if(confirm('Xóa hình này ?')){
                        var idHinh = $(this).attr('idHinh');
                        $.post('ajax/xoahinh.php',{idHinh:idHinh},function(data){
                            $('div[idHinh=' + idHinh + ']').remove();    
                        });
                    }
                });
                $('#idTL').change(function(){
                    $.post('ajax/getloai.php',{idTL:$(this).val()},function(data){
                        $('#idLT').html(data);
                    })
                })
	});
</script>
<style>
#div_upload{font-size:13px;text-align:center}

</style>
<form action="" method="post" name="form_add_dm_ks">
<div id="admin_navigation">
	<div style="float:left;width:90%">
		<h3>Quản lý sản phẩm: cập nhật</h3>
    </div>
     <div class="clear"></div> 
	<div style="float:left;width:5%;padding-top:5px">
    	<input type="submit" class="save" name="btnSumit" value=""/><br />		
        <span>Save</span>
    </div>
    <div style="float:left;width:5%;padding-top:5px">
    	<input type="reset" class="cancel" name="btnCancel" value=""/><br />		
        <span>Reset</span>
    </div>
    <div class="clr"></div>
    <div style="clear:both"></div>
</div>
    <div style="clear:both"></div>
<div id="main_admin">
	
	<div id="main_left" style="width:70%">
    	<fieldset>
        	<legend>Thông tin chung</legend>
            	<table>                	
                   	<tr>
                    	<td>Loại SP</td>
                        <td colspan="3">
                         
                            <select name="idTL" id="idTL">
                                <option value="0">--Chọn loại--</option>
                                <?php 
                                $loaisp = $tl->TheLoai_List();
                                while($row = mysql_fetch_assoc($loaisp)){
                                ?>
                                <option <?php echo ($row_ct['idTL']==$row['idTL']) ? "selected" : '';?> value="<?php echo $row['idTL']; ?>"><?php echo $row['TenTL']; ?></option>
                                <?php } ?>
                            </select>
                               
                        </td>   
                    </tr>
                    <tr>
                    	<td>Hãng</td>
                        <td colspan="3">
                         
                            <select name="idLT" id="idLT">
                                <option value="0">--Chọn hãng--</option>
                                <?php 
                                $hang = $lt->LoaiTin_List();
                                while($row = mysql_fetch_assoc($hang)){
                                ?>
                                <option <?php echo ($row_ct['idTL']==$row['idLT']) ? "selected" : '';?> value="<?php echo $row['idLT']; ?>"><?php echo $row['TenLT']; ?></option>
                                <?php } ?>
                            </select>
                               
                        </td>   
                    </tr>                       
                   
                     <tr>
                    <td>Mã SP</td>
                    <td><input type="text" name="MaSP" id="MaSP" class="tf" value="<?php echo $row_ct['MaSP']?>" /></td>                        
                </tr>    
                <tr>
                    <td width="15%">Giá</td>
                    <td><input type="text" name="Gia" id="Gia" class="tf" value="<?php echo $row_ct['Gia']?>" />
                        <span class="error"><?php echo $loi['Gia'];?></span>
                    </td>                        
                </tr>  
                 <tr>
                    <td width="15%">Xuất xứ</td>
                    <td>
                    	<input type="text" name="XuatXu" id="XuatXu" class="tf" value="<?php echo $row_ct['XuatXu']?>" />            
                    </td>                        
                </tr>                                
                <tr>
                    <td width="15%">Bảo hành</td>
                    <td><input type="text" name="BaoHanh" id="BaoHanh" class="tf" style="width:100px" value="<?php echo $row_ct['BaoHanh']?>" />
                        tháng
                    </td>                        
            	</tr>
                <tr>
                    <td>&nbsp;</td>
                    <td>
                       <input type="checkbox" name="AnHien" <?php echo ($row_ct['AnHien']==0) ? "checked" : '';?> /> Ẩn &nbsp;&nbsp;&nbsp;&nbsp;
                       <input type="checkbox" name="NoiBat" <?php echo ($row_ct['NoiBat']==1) ? "checked" : ''; ?> /> Nổi bật &nbsp;&nbsp;&nbsp;&nbsp;
                       <input type="checkbox" name="BanChay" <?php echo ($row_ct['BanChay']==1) ? "checked" : ''; ?> /> Bán chạy 
                    </td>                        
                    
                </tr>   
                <tr>
                    <td>Hình ảnh</td>
                    <td>            
                        <?php $rs_hinh = mysql_query("SELECT * FROM hinhsp WHERE idSP = $idSP");
                        if(mysql_num_rows($rs_hinh)>0){
                        ?>
                        <div style="width:100%;height:200px">
                        <?php 
                        $hinhanhcu = '';
                        while($row_img = mysql_fetch_assoc($rs_hinh)){    
                            $hinhanhcu.= $row_img['url'];
                        ?>
                            <div style="width:120px;float:left;height:200px;margin-right:10px;text-align:center" idHinh="<?php echo $row_img['idHinh']; ?>">
                                <img src="../<?php echo $row_img['url']; ?>" width="100px" height="100px" /><br /><br />
                                <input type='radio' name='hinh_dai_dien' value='../<?php echo  $row_img['url']; ?>' 
                                <?php if($row_ct['UrlHinh']==$row_img['url']) echo "checked"; ?> />
                                <br /><br />
                                <span class="xoa_img" style="cursor:pointer" idHinh="<?php echo $row_img['idHinh']; ?>">Xóa hình</span>
                            </div>
                            <?php }?> 
                         <input type="hidden" name="hinh_anh_cu" value="<?php echo $hinhanhcu; ?>" />   
                        </div>
                        <?php } ?>
                        <div style="clear:both"></div>
                        <div id="hinhanh">

                        </div>
                        <div style="clear:both"></div>
                        <input type="button" id="btnUpload" value="Thêm hình" />
                    </td>                        
                </tr>                                     
                    
                              
                </table>            
        </fieldset>
    </div>	   
    <div id="main_details" style="clear:both;padding-top: 20px">
        <fieldset class="details_form">
        	<legend>++ Thông tin chi tiết ++</legend>
            <table>                          
                <tr>
                    <td>Tính năng</td>
                    <td>
                        <div style="width:800px;overflow: hidden">
                        <textarea class="meta" name="TinhNang" id="TinhNang"><?php echo $row_ct['TinhNang']?></textarea>
                        <script type="text/javascript">
                        var editor = CKEDITOR.replace( 'TinhNang',{
                            uiColor : '#9AB8F3',
                            language:'vi',
                            skin:'office2003',
                            filebrowserImageBrowseUrl : 'ckfinder/ckfinder.html?Type=Images',
                            filebrowserFlashBrowseUrl : 'ckfinder/ckfinder.html?Type=Flash',
                            filebrowserImageUploadUrl :'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
                            filebrowserFlashUploadUrl : 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash',

                            toolbar:[
                            ['Source','-','Save'],
                            ['Copy','Paste','PasteText','PasteFromWord'],
                            ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
                            ['NumberedList','BulletedList'],
                            ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
                            ['Link','Unlink','Anchor','Image'],                           
                            ['Styles','Format','Font','FontSize'],
                            ['TextColor','BGColor']                         
                            ]
                        });		
                        </script>
                        </div>         
                    </td>                        
                </tr>
                 <tr>
                    <td>Thông số kỹ thuật</td>
                    <td>
                        <div style="width:800px;overflow: hidden">
                        <textarea class="meta" name="MoTa" id="MoTa"><?php echo $row_ct['MoTa']?></textarea>
                        <script type="text/javascript">
                        var editor = CKEDITOR.replace( 'MoTa',{
                            uiColor : '#9AB8F3',
                            language:'vi',
                            skin:'office2003',
                            filebrowserImageBrowseUrl : 'ckfinder/ckfinder.html?Type=Images',
                            filebrowserFlashBrowseUrl : 'ckfinder/ckfinder.html?Type=Flash',
                            filebrowserImageUploadUrl :'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
                            filebrowserFlashUploadUrl : 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash',

                            toolbar:[
                            ['Source','-','Save'],
                            ['Copy','Paste','PasteText','PasteFromWord'],
                            ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
                            ['NumberedList','BulletedList'],
                            ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
                            ['Link','Unlink','Anchor','Image'],                           
                            ['Styles','Format','Font','FontSize'],
                            ['TextColor','BGColor']                         
                            ]
                        });		
                        </script>
                        </div>          
                    </td>                        
                </tr>
                                         
            </table>
        </fieldset>
        
    </div>
   
    <div class="clr"></div>
</div>
</form>
<div id="div_upload" style="display:none">
    <form id="upload_images" method="post" enctype="multipart/form-data" enctype="multipart/form-data" action="ajax.php">
        <div style="margin: auto;">       
            <img src="images/add.png" id="add_images" width="32" />
            <div id="wrapper_input_files">
            	<input type="file" name="images[]" /><br />
                <input type="file" name="images[]" /><br />
                <input type="file" name="images[]" /><br />
            </div>            
            <div class="clear"></div>       
            <button style="margin-top: 10px;"class="button_colour" type="submit" id="btn_upload_images">                
                <a href="#">Upload</a>
            </button>        
        </div>
        
    </form>
</div>

